home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / CMPLTPAS / DIRSTRIN.PAS < prev    next >
Pascal/Delphi Source File  |  1988-07-14  |  3KB  |  67 lines

  1. {->>>>DIRToString<<<<------------------------------------------}
  2. {                                                              }
  3. { Filename : DIRSTRIN.SRC -- Last Modified 6/9/88              }
  4. {                                                              }
  5. { This routine returns a String value containing all the       }
  6. { significant information from a directory record, formatted   }
  7. { in a fashion similar to that used by the DOS DIR command     }
  8. { when it displays a file and its information.  A typical      }
  9. { string returned by DIRToString would look like this:         }
  10. {                                                              }
  11. {       DIRSTRIN.BAK 1697  01/07/87   3:04p                    }
  12. {                                                              }
  13. { Type DIRRec must be predefined.                              }
  14. {                                                              }
  15. {     From: COMPLETE TURBO PASCAL 5.0  by Jeff Duntemann       }
  16. {    Scott, Foresman & Co., Inc. 1988   ISBN 0-673-38355-5     }
  17. {--------------------------------------------------------------}
  18.  
  19. FUNCTION DIRToString(InputDIR : DIRRec) : String;
  20.  
  21. CONST
  22.   Blanker = '                                              ';
  23.  
  24. VAR
  25.   Temp,WorkString : String80;
  26.   DotPos : Integer;
  27.  
  28. BEGIN
  29.   WITH InputDIR DO
  30.     BEGIN
  31.       Temp := '                                        ';
  32.       {If the entry has the directory attribute, format differently: }
  33.       IF (Attrib AND $10) <> 0 THEN    { Bit 4 is the directory attribute }
  34.         BEGIN
  35.           Insert(FileName,Temp,1);  { No extensions on subdirectory names }
  36.           Insert('<DIR>',Temp,14)   { Tell the world it's a subdirectory  }
  37.         END
  38.       ELSE
  39.         {This compound statement separates the file from its extension  }
  40.         { and converts the file size to a string.  Note that we did not }
  41.         { insert a file size figure into Temp for subdirectory entries. }
  42.         BEGIN
  43.           DotPos := Pos('.',FileName);
  44.           IF DotPos > 0 THEN  { File name has an extension }
  45.             WorkString := Copy(FileName,1,DotPos-1) +
  46.               Copy(Blanker,1,9-DotPos) + '.' +
  47.               Copy(FileName,DotPos+1,Length(FileName)-DotPos)
  48.           ELSE
  49.             WorkString := FileName + Copy(Blanker,1,8-Length(FileName)) + '.';
  50.           Insert(WorkString,Temp,1);
  51.           Str(FileSize:7,WorkString);
  52.           Insert(WorkString,Temp,15)
  53.         END;
  54.       WITH DateStamp DO
  55.         BEGIN
  56.           { This is what it takes to assemble three separate integer  }
  57.           { figures for month, day, and year into a string equivalent.}
  58.           IF Month < 10 THEN Insert('0',DateString,1);
  59.           IF Day < 10 THEN Insert('0',DateString,4);
  60.           Insert(DateString,Temp,24);
  61.         END;
  62.       Insert(TimeStamp.TimeString,Temp,34); { Finally, insert the time }
  63.     END;
  64.   Delete(Temp,42,Length(Temp)-42);
  65.   DIRToString := Temp
  66. END;
  67.